<template>
  <div>
    <a-card>
      <a-form :form="form">
        <a-row :gutter="48">
          <a-col :md="12" :sm="12">
            <a-form-item >单位代码：{{postParams.ssyxm?postParams.ssyxm:'000'}}</a-form-item>
          </a-col>
          <a-col :md="12" :sm="12">
            <a-form-item >联系部门：{{postParams.yxmc?postParams.yxmc:'研究生院'}}</a-form-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-item label="地址">
              <a-textarea v-decorator="[
                  'zsdz',
                  {
                    rules: [{ required: true, message: '请输入招生说明!' }],
                  },
                  {initialValue:postParams.zsdz}
                ]"
                rows="4" />
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="电话" >
              <a-input placeholder="请输入电话" v-decorator="['zsdh',
              {
                rules: [{ required: true, message: '请输入电话!' }],
              },
              {initialValue:postParams.zsdh}
              ]"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="联系人">
              <a-input placeholder="请输入联系人" v-decorator="['zslxr',
              {
                rules: [{ required: true, message: '请输入联系人!' }],
              },
              {initialValue:postParams.zslxr}
              ]"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="8">
            <a-form-item label="邮政编码">
              <a-input placeholder="请输入邮政编码" v-decorator="['yzbm',
              {
                rules: [{ required: true, message: '请输入邮政编码!' }],
              },
              {initialValue:postParams.yzbm}
              ]"/>
            </a-form-item>
          </a-col>
          <a-col :md="24" :sm="24">
            <a-form-item label="招生说明">
              <a-textarea v-decorator="[ 'zssm',{initialValue:postParams.zssm}]"
                rows="4" />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-card>

    <div class="ant-pro-footer-toolbar">
      <a-button style="float: right;margin-top: 10px;" @click="handleSubmit" :loading="loadingBtn" type="primary">保存</a-button>
    </div>
  </div>
</template>
<script>
  import {
    mapState
  } from 'vuex'
  const selectArr = ['TYPE0320', 'TYPE0321', 'TYPE0011', 'TYPE0360', 'TYPE0342', 'TYPE0018', 'TYPE0023', 'TYPE0126']

  export default {
    data() {
      return {
        selectMenu: {},
        loading: false,
        imageUrl: '',
        loadingBtn: false,
        postParams:{
          ssyxm:'',
          yxmc:'',
          yzbm:'',
          zsdh:'',
          zsdz:'',
          zssm:'',
          zslxr:''
        }
      }
    },
    beforeCreate() {
      this.form = this.$form.createForm(this)
    },
    computed: {
      ...mapState({
        TYPE0126: state => state.app['TYPE0126']
      })
    },
    created() {
      selectArr.forEach(v => {
        this.$store.dispatch('app/setDictionary', v)
      })
      this.initSelectMenu()
      this.getInitValue()
    },
    methods: {
      initSelectMenu() {
        let allRequest = [
          this.$api.base.collegeAll(),
          this.$api.base.areaList()
        ]
        Promise.all(allRequest).then(res => {
          this.selectMenu = {
            yx: res[0].data
          }
        })
      },
      handleSearch() {},
      handleSubmit() {
        this.form.validateFields((err, values) => {
          if (err) {
            this.$message.error('请输入必填项')
            return
          }
          var params = {
            ssyxm:this.postParams.ssyxm?this.postParams.ssyxm:'000',
            yxmc:this.postParams.yxmc?this.postParams.yxmc:'研究生院',
            yzbm:this.form.getFieldsValue().yzbm,
            zsdh:this.form.getFieldsValue().zsdh,
            zsdz:this.form.getFieldsValue().zsdz,
            zslxr:this.form.getFieldsValue().zslxr,
            zssm:this.form.getFieldsValue().zssm
          }
          console.log(params)
          this.$api.doctorRecruit.basicInfoAdd(params).then(res => {
            this.$message.success('保存成功')
            this.getInitValue()
            // this.$refs.stuInfo.form.resetFields()
            // this.$refs.scoreInfo.form.resetFields()
            // this.$refs.stuStatusInfo.form.resetFields()
            // this.$router.push('/student/info/search')
          })
        })
      },
      getInitValue(){
        this.$api.doctorRecruit.basicInfoId({"sortField":"createDate"}).then( res =>{
            if(res.data){
                this.postParams = res.data
                for(var key in res.data){
                  this.form.getFieldDecorator(key, {initialValue: res.data[key]})
                }
              // console.log(this.postParams)
            }
        })
      }
    }
  }
</script>
